<?php

namespace app\statis\model;

use app\common\model\Product;

class ProductModel extends Product
{
    /**
     * 商品数据统计
     * 上架、下架商品数
     */
    public function statProduct()
    {
        $upper_shelf_num = $this->where(['is_show' => Product::IS_SHOW_YES])->count();
        $lower_shelf_num = $this->where(['is_show' => Product::IS_SHOW_NO])->count();
        return [
            'lower_shelf_num'   => $lower_shelf_num,
            'upper_shelf_num'   => $upper_shelf_num,
        ];
    }

    /**
     * 通过商品id获取商品数据
     *
     * @param $product_id
     * @return array|\PDOStatement|string|\think\Model|null
     *
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getOneById($product_id)
    {
        return $this->where(['product_id' => $product_id])->find();
    }
}